export default {
  data() {
    return {
      //收入类型选择
      incomeIndex: 0,
      incomePicker: [{
        type: 0,
        name: '综合所得'
      },
      {
        type: 1,
        name: '工资、薪金所得'
      },
      {
        type: 2,
        name: '经营所得'
      },
      {
        type: 3,
        name: '劳务报酬所得'
      },
      {
        type: 4,
        name: '稿酬所得'
      },
      {
        type: 5,
        name: '特许权使用费所得'
      },
      {
        type: 6,
        name: '财产租赁所得'
      },
      {
        type: 7,
        name: '财产转让所得'
      },
      {
        type: 8,
        name: '偶然所得'
      }
      ],
      taxIncome: '', //税前收入,
      socialCost: '', //社会保险费用
      fiexdBands: 60000, //免征税额
      resultShow: false,

      //子女教育专项附加扣除
      childBox: [
        {
          value: '1',
          checked: false
        }
      ],
      childIndex: 0,
      childNum: [1, 2, 3, 4, 5, 6, 7, 8, 9],
      deductIndex: 0,
      deductWay: ['单独承担100%扣除', '夫妻双方50%扣除'],
      childBands: 24000,
      childShow: false,

      //继续教育专项附加扣除
      educationBox: [
        {
          value: '1',
          checked: false
        }
      ],
      educationShow: false,
      educationIndex: 0,
      educationType: ['学历教育', '职业资格教育'],
      educationBands: 4800,

      //大病医疗专项附加扣除
      illnessBox: [
        {
          value: '1',
          checked: false
        }
      ],
      illnessShow: false,
      illnessBands: '',

      //居住专项附加扣除、
      homeBox: [
        {
          value: '1',
          checked: false
        }
      ],
      homeShow: false,
      homeIndex: 0,
      homeType: ['首房贷款', '住房租金'],
      homeBands: 12000,
      rentIndex: 0,
      rentType: [9600, 13200, 18000],
      rentShow: false,

      //赡养老人专项附加扣除
      oldBox: [
        {
          value: '1',
          checked: false
        }
      ],
      oldShow: false,
      oldIndex: 0,
      oldWay: ['独生子女', '非独生子女'],
      oldBands: 36000,
      oldChildIndex: 0,
      oldChildNum: [
        {
          id: 1,
          num: 2
        },
        {
          id: 2,
          num: 3
        },
        {
          id: 3,
          num: 4
        },
        {
          id: 4,
          num: 5
        },
        {
          id: 5,
          num: 6
        },
        {
          id: 6,
          num: 7
        },
        {
          id: 7,
          num: 8
        },
        {
          id: 8,
          num: 9
        }
      ],
      oldChildShow: false,

      //最终结果
      shouldTax: 0, //应缴税款
      taxOutcome: 0, //税后收入
      shouldIncome: 0, //应纳税所得额
      applyTax: 0, //适用税率
      quickCount: 0, //速算扣除数
      personalShow: true,

      //经营所得
      manageShow: false,
      incomePrice: '',
      deductExpend: '',
      monthBands: 5000,
      manageIndex: -1,
      manageTime: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],

      //劳务报酬所得
      labourShow: false,
      labourPrice: '',
      expendPrice: 0,

      //稿酬所得
      remunerationShow: false,
      remunerationPrice: '',

      //特权使用费
      privilegeShow: false,
      privilegePrice: '',

      //财产租赁所得
      taxPicker: ['20%', '10%'],
      taxIndex: 0,
      leasePrice: '',
      leaseDeduct: '',
      repairPrice: '',
      leaseShow: false,

      //财产转让所得
      makeOverPrice: '',
      originalValue: '',
      reasonableExpend: '',
      makeOverShow: false,

      //偶然所得
      accidentPrice: '',
      accidentShow: false
    }
  },
  watch: {
    childDeduct(val) {
      if (val.deductIndex != 0) {
        this.childBands = 24000 * (val.childIndex + 1) / 2
      } else {
        this.childBands = 24000 * (val.childIndex + 1)
      }
    },
  },

  computed: {
    childDeduct() {
      const { childIndex, deductIndex } = this
      return {
        childIndex,
        deductIndex
      }
    }
  },
  methods: {

    //收入方式选择
    incomeChange(e) {
      this.resultShow = false
      this.incomeIndex = e.detail.value
      let val = e.detail.value
      if (val == 0 || val == 1) {
        this.personalShow = true
        this.manageShow = false
        this.labourShow = false
        this.remunerationShow = false
        this.privilegeShow = false
        this.leaseShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 2) {
        this.manageShow = true
        this.personalShow = false
        this.labourShow = false
        this.remunerationShow = false
        this.privilegeShow = false
        this.leaseShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 3) {
        this.labourShow = true
        this.personalShow = false
        this.manageShow = false
        this.remunerationShow = false
        this.privilegeShow = false
        this.leaseShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 4) {
        this.remunerationShow = true
        this.personalShow = false
        this.manageShow = false
        this.labourShow = false
        this.privilegeShow = false
        this.leaseShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 5) {
        this.privilegeShow = true
        this.remunerationShow = false
        this.personalShow = false
        this.manageShow = false
        this.labourShow = false
        this.leaseShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 6) {
        this.leaseShow = true
        this.privilegeShow = false
        this.remunerationShow = false
        this.personalShow = false
        this.manageShow = false
        this.labourShow = false
        this.makeOverShow = false
        this.accidentShow = false
      } else if (val == 7) {
        this.makeOverShow = true
        this.leaseShow = false
        this.privilegeShow = false
        this.remunerationShow = false
        this.personalShow = false
        this.manageShow = false
        this.labourShow = false
        this.accidentShow = false
      } else if (val == 8) {
        this.accidentShow = true
        this.makeOverShow = false
        this.leaseShow = false
        this.privilegeShow = false
        this.remunerationShow = false
        this.personalShow = false
        this.manageShow = false
        this.labourShow = false
      }
    },


    //重置
    resetBtn() {
      this.resultShow = false
      if (this.incomeIndex == 0 || this.incomeIndex == 1) {
        this.taxIncome = ''
        this.socialCost = ''
        this.childBox[0].checked = false
        this.childShow = false
        this.educationBox[0].checked = false
        this.educationShow = false
        this.illnessBox[0].checked = false
        this.illnessShow = false
        this.homeBox[0].checked = false
        this.homeShow = false
        this.oldBox[0].checked = false
        this.oldShow = false
      } else if (this.incomeIndex == 2) {
        this.incomePrice = ''
        this.deductExpend = ''
        this.manageIndex = -1
      } else if (this.incomeIndex == 3) {
        this.labourPrice = ''
      } else if (this.incomeIndex == 4) {
        this.remunerationPrice = ''
      } else if (this.incomeIndex == 5) {
        this.privilegePrice = ''
      } else if (this.incomeIndex == 6) {
        this.leasePrice = ''
        this.leaseDeduct = ''
        this.repairPrice = ''
        this.taxIndex = 0
      } else if (this.incomeIndex == 7) {
        this.makeOverPrice = ''
        this.originalValue = ''
        this.reasonableExpend = ''
      } else if (this.incomeIndex == 8) {
        this.accidentPrice = ''
      }

    },

    //子女教育专项附加税选择
    childCheck(e) {
      if (e.detail.value.length > 0) {
        this.childShow = true
      } else {
        this.childShow = false
      }
      var items = this.childBox,
        values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        items[i].checked = false;
        for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
          if (items[i].value == values[j]) {
            items[i].checked = true;
            break
          }
        }
      }
    },
    childChange(e) {
      this.childIndex = e.detail.value
    },
    deductChange(e) {
      this.deductIndex = e.detail.value
    },

    //继续教育专项附加扣除
    educationCheck(e) {
      if (e.detail.value.length > 0) {
        this.educationShow = true
      } else {
        this.educationShow = false
      }
      var items = this.educationBox,
        values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        items[i].checked = false;
        for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
          if (items[i].value == values[j]) {
            items[i].checked = true;
            break
          }
        }
      }
    },
    educationChange(e) {
      this.educationIndex = e.detail.value
      if (e.detail.value == 0) {
        this.educationBands = 4800
      } else {
        this.educationBands = 3600
      }
    },

    //大病医疗专项附加扣除
    illnessCheck(e) {
      if (e.detail.value.length > 0) {
        this.illnessShow = true
      } else {
        this.illnessShow = false
      }
      var items = this.illnessBox,
        values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        items[i].checked = false;
        for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
          if (items[i].value == values[j]) {
            items[i].checked = true;
            break
          }
        }
      }
    },

    //居住专项附加扣除
    homeChange(e) {
      this.homeIndex = e.detail.value
      if (e.detail.value == 0) {
        this.rentShow = false
      } else {
        this.rentShow = true
      }
    },
    rentChange(e) {
      this.rentIndex = e.detail.value
    },

    homeCheck(e) {
      if (e.detail.value.length > 0) {
        this.homeShow = true
      } else {
        this.homeShow = false
      }
      var items = this.homeBox,
        values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        items[i].checked = false;
        for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
          if (items[i].value == values[j]) {
            items[i].checked = true;
            break
          }
        }
      }
    },

    //赡养老人专项附加扣除
    oldCheck(e) {
      if (e.detail.value.length > 0) {
        this.oldShow = true
      } else {
        this.oldShow = false
      }
      var items = this.oldBox,
        values = e.detail.value;
      for (var i = 0, lenI = items.length; i < lenI; ++i) {
        items[i].checked = false;
        for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
          if (items[i].value == values[j]) {
            items[i].checked = true;
            break
          }
        }
      }
    },
    oldChange(e) {
      this.oldIndex = e.detail.value
      if (e.detail.value == 1) {
        this.oldChildShow = true
        this.oldBands = 36000 / this.oldChildNum[this.oldChildIndex].num
      } else {
        this.oldChildShow = false
        this.oldBands = 36000
      }
    },
    oldChildChange(e) {
      this.oldChildIndex = e.detail.value
      this.oldBands = 36000 / this.oldChildNum[this.oldChildIndex].num
    },

    //经营所得
    manageChange(e) {
      this.manageIndex = e.detail.value
    },

    //财产租赁所得
    taxChange(e) {
      this.taxIndex = e.detail.value
    },

    //计算
    countBtn() {
      if (this.incomeIndex == 0 || this.incomeIndex == 1) {
        if (this.incomeIndex == -1) {
          this.$tools.msg('请选择收入类型')
          return
        }
        if (this.taxIncome == '') {
          this.$tools.msg('请填写税前年收入')
          return
        }
        var childBands;
        var educationBands;
        var illnessBands;
        var homeBands;
        var oldBands;
        if (this.childShow) {
          childBands = this.childBands
        } else {
          childBands = 0
        }
        if (this.educationShow) {
          educationBands = this.educationBands
        } else {
          educationBands = 0
        }
        if (this.illnessShow) {
          if (this.illnessBands < 15000 || this.illnessBands > 80000) {
            this.$tools.msg('大病扣除需在规定范围之内')
            return
          }
          illnessBands = Number(this.illnessBands)
        } else {
          illnessBands = 0
        }
        if (this.homeShow) {
          if (this.rentShow) {
            homeBands = this.rentType[this.rentIndex]
          } else {
            homeBands = this.homeBands
          }
        } else {
          homeBands = 0
        }
        if (this.oldShow) {
          oldBands = this.oldBands
        } else {
          oldBands = 0
        }
        console.log(childBands, educationBands, illnessBands, homeBands, oldBands)
        const finalPrice = this.taxIncome - this.socialCost - childBands - educationBands - illnessBands - homeBands - oldBands - 60000
        if (finalPrice <= 0) {
          this.$tools.msg('应纳税所得额不能小于等于0')
          return
        }
        this.shouldIncome = finalPrice
        if (0 < finalPrice && finalPrice <= 36000) {
          const rate = finalPrice * 0.03
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 3 + '%'
          this.quickCount = 0
        } else if (36000 < finalPrice && finalPrice <= 144000) {
          const rate = finalPrice * 0.1 - 2520
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 10 + '%'
          this.quickCount = 2520
        } else if (144000 < finalPrice && finalPrice <= 300000) {
          const rate = finalPrice * 0.2 - 16920
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 20 + '%'
          this.quickCount = 16920
        } else if (300000 < finalPrice && finalPrice <= 420000) {
          const rate = finalPrice * 0.25 - 31920
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 25 + '%'
          this.quickCount = 31920
        } else if (420000 < finalPrice && finalPrice <= 660000) {
          const rate = finalPrice * 0.3 - 52920
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 30 + '%'
          this.quickCount = 52920
        } else if (660000 < finalPrice && finalPrice <= 960000) {
          const rate = finalPrice * 0.35 - 85920
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 35 + '%'
          this.quickCount = 85920
        } else if (960000 < finalPrice) {
          const rate = finalPrice * 0.45 - 181920
          this.shouldTax = rate
          this.taxOutcome = this.taxIncome - rate
          this.applyTax = 45 + '%'
          this.quickCount = 181920
        }
        this.resultShow = true
      } else if (this.incomeIndex == 2) {
        const finalPrice = this.incomePrice - this.deductExpend - (this.manageIndex + 1) * 5000
        if (finalPrice <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        this.shouldIncome = finalPrice
        if (0 < finalPrice && finalPrice <= 30000) {
          const rate = finalPrice * 0.05
          this.shouldTax = rate
          this.taxOutcome = this.incomePrice - rate
          this.applyTax = 5 + '%'
          this.quickCount = 0
        } else if (30000 < finalPrice && finalPrice <= 90000) {
          const rate = finalPrice * 0.1 - 1500
          this.shouldTax = rate
          this.taxOutcome = this.incomePrice - rate
          this.applyTax = 10 + '%'
          this.quickCount = 1500
        } else if (90000 < finalPrice && finalPrice <= 300000) {
          const rate = finalPrice * 0.2 - 10500
          this.shouldTax = rate
          this.taxOutcome = this.incomePrice - rate
          this.applyTax = 20 + '%'
          this.quickCount = 10500
        } else if (300000 < finalPrice && finalPrice <= 500000) {
          const rate = finalPrice * 0.3 - 40500
          this.shouldTax = rate
          this.taxOutcome = this.incomePrice - rate
          this.applyTax = 30 + '%'
          this.quickCount = 40500
        } else if (500000 < finalPrice) {
          const rate = finalPrice * 0.35 - 65500
          this.shouldTax = rate
          this.taxOutcome = this.incomePrice - rate
          this.applyTax = 35 + '%'
          this.quickCount = 65500
        }
        this.resultShow = true
      } else if (this.incomeIndex == 3) {
        if (this.labourPrice == '') {
          this.$tools.msg('请填写收入金额')
          return
        }
        if (this.labourPrice - 800 <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        var finalPrice;
        if (this.labourPrice > 800 && this.labourPrice <= 4000) {
          finalPrice = this.labourPrice - 800
          this.expendPrice = 800
        } else if (this.labourPrice > 4000) {
          finalPrice = this.labourPrice - this.labourPrice * 0.2
          this.expendPrice = this.labourPrice * 0.2
        }
        this.shouldIncome = finalPrice
        if (0 < finalPrice && finalPrice <= 20000) {
          const rate = finalPrice * 0.2
          this.shouldTax = rate
          this.taxOutcome = this.labourPrice - rate
          this.applyTax = 20 + '%'
          this.quickCount = 0
        } else if (20000 < finalPrice && finalPrice <= 50000) {
          const rate = finalPrice * 0.3 - 2000
          this.shouldTax = rate
          this.taxOutcome = this.labourPrice - rate
          this.applyTax = 30 + '%'
          this.quickCount = 2000
        } else if (5000 < finalPrice) {
          const rate = finalPrice * 0.4 - 2000
          this.shouldTax = rate
          this.taxOutcome = this.labourPrice - rate
          this.applyTax = 40 + '%'
          this.quickCount = 7000
        }
        this.resultShow = true
      } else if (this.incomeIndex == 4) {
        var finalPrice;
        if (this.remunerationPrice == '') {
          this.$tools.msg('请填写收入金额')
          return
        }
        if (this.remunerationPrice - 800 <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        if (this.remunerationPrice > 800 && this.remunerationPrice <= 4000) {
          finalPrice = this.remunerationPrice - 800
          this.expendPrice = 800
        } else if (this.remunerationPrice > 4000) {
          finalPrice = this.remunerationPrice - this.remunerationPrice * 0.2
          this.expendPrice = this.remunerationPrice * 0.2
        }
        if (finalPrice <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        this.shouldIncome = finalPrice
        const rate = finalPrice * 0.14
        this.shouldTax = rate
        this.taxOutcome = this.remunerationPrice - rate
        this.applyTax = 14 + '%'
        this.quickCount = 0
        this.resultShow = true
      } else if (this.incomeIndex == 5) {
        if (this.privilegePrice == '') {
          this.$tools.msg('请填写收入金额')
          return
        }
        if (this.privilegePrice - 800 <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        var finalPrice;
        if (this.privilegePrice > 800 && this.privilegePrice <= 4000) {
          finalPrice = this.privilegePrice - 800
          this.expendPrice = 800
        } else if (this.privilegePrice > 4000) {
          finalPrice = this.privilegePrice - this.privilegePrice * 0.2
          this.expendPrice = this.privilegePrice * 0.2
        }
        if (finalPrice <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        this.shouldIncome = finalPrice
        const rate = finalPrice * 0.2
        this.shouldTax = rate
        this.taxOutcome = this.privilegePrice - rate
        this.applyTax = 20 + '%'
        this.quickCount = 0
        this.resultShow = true
      } else if (this.incomeIndex == 6) {
        if (this.repairPrice > '800') {
          this.$tools.msg('每次(月)修缮费用上限为800')
          return
        }
        var price = this.leasePrice - this.leaseDeduct - this.repairPrice
        var tax;
        if (price <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        if (this.taxIndex == 0) {
          tax = 0.2
        } else {
          tax = 0.1
        }
        if (price > 800 && price <= 4000) {
          finalPrice = price - 800
        } else if (price > 4000) {
          finalPrice = price - price * 0.2
        }
        this.shouldIncome = finalPrice
        const rate = finalPrice * tax
        this.shouldTax = rate
        this.taxOutcome = this.leasePrice - rate
        this.applyTax = tax * 100 + '%'
        this.resultShow = true
      } else if (this.incomeIndex == 7) {
        var price = this.makeOverPrice - this.originalValue - this.reasonableExpend
        if (price <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        const rate = price * 0.2
        this.shouldIncome = price
        this.shouldTax = rate
        this.taxOutcome = this.makeOverPrice - rate
        this.applyTax = 20 + '%'
        this.resultShow = true
      } else if (this.incomeIndex == 8) {
        if (this.accidentPrice <= 0) {
          this.$tools.msg('您未达到纳税标准无需交税')
          return
        }
        const rate = this.accidentPrice * 0.2
        this.shouldIncome = Number(this.accidentPrice)
        this.shouldTax = rate
        this.taxOutcome = this.accidentPrice - rate
        this.applyTax = 20 + '%'
        this.resultShow = true
      }
    }
  }
}